import { request } from '@umijs/max';

export interface StateType {
  status?: 'ok' | 'error';
  currentAuthority?: 'user' | 'guest' | 'admin';
}

export interface UserRegisterParams {
  mail: string;
  password: string;
  confirm: string;
  mobile: string;
  captcha: string;
  prefix: string;
}

export async function fakeRegister(params: UserRegisterParams) {
  return request('/api/register', {
    method: 'POST',
    data: params,
  });
}

// 注册邮箱  验证码发送
export async function sendSmsCode(body: any, options?: { [key: string]: any }) {
  return request<{
    code: number;
    data: {
      resultMessage: string;
      cellId: string;
    };
    msg: string | null;
  }>('/admin-api/system/auth/send-sms-code', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}

// 注册
export async function registerApi(body: any, options?: { [key: string]: any }) {
  return request<{
    code: number;
    data: {
      resultMessage: string;
      cellId: string;
    };
    msg: string | null;
  }>('/admin-api/system/auth/register', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}

// 忘记密码
export async function resetPassword(body: any, options?: { [key: string]: any }) {
  return request<{
    code: number;
    data: {
      resultMessage: string;
      cellId: string;
    };
    msg: string | null;
  }>('/admin-api/system/auth/reset-password', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}